package com.hzdesk.media.matvector.koreabatch.client.my_paperless.base;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.hzdesk.media.matvector.koreabatch.client.my_paperless.inter.IonClickedItemListenter;

import java.util.List;

/**
 * Created by Administrator on 2018/8/7.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public  abstract class BaseAdapter<T> extends RecyclerView.Adapter<BaseViewHolder> implements View.OnClickListener {


    public IonClickedItemListenter mIonClickedItemListenter = null;
    public List<T> mlist;
    public Context tContext;

    public BaseAdapter(Context mContext) {
        this.tContext = mContext;
    }
    public void setmIonClickedItemListenter(IonClickedItemListenter mIonClickedItemListenter) {
        this.mIonClickedItemListenter = mIonClickedItemListenter;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(getItemLayout(), parent, false);
           BaseViewHolder mBaseViewHolder = getItemViewHolder(view);
            view.setOnClickListener(this);
            return mBaseViewHolder;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        onMyBindViewHolder(holder,position);

    }

    @Override
    public int getItemCount() {
        return mlist == null ? 0 : mlist.size() ;
    }
    /**
     * @desc 添加数据的方法
     * */
    public void AddItemDate(List<T> mdate){
        mlist = mdate;
        notifyDataSetChanged();
    }
    /**
     * @desc item 点击事件
     * */
    @Override
    public void onClick(View view) {
        if(mIonClickedItemListenter != null){
            mIonClickedItemListenter.onClickedItem(view);
        }
    }
    /**
     * @desc 提供item布局
     * */
    protected abstract int getItemLayout();
    /**
     * @desc 提供 item的ViewHolder
     * */
    protected abstract BaseViewHolder getItemViewHolder(View view);

    /**
     * @desc 数据与控件绑定
     * */
    protected abstract void onMyBindViewHolder(BaseViewHolder holder, int position);
}
